package com.avic.modules.equipment.rest;

import com.avic.modules.equipment.service.EquipmentOperationService;
import com.avic.modules.equipment.service.dto.EquipmentOperationQuery;
import com.avic.modules.equipment.service.dto.EquipmentQueryCriteria;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

/**
 * @author zhangzikang
 * @date 2022-08-14
 */
@Api(tags = "设备管理: 设备运行记录")
@RestController
@RequestMapping("/api/equipment/operation")
@AllArgsConstructor
public class EquipmentOperationController {

    private final EquipmentOperationService operationService;

    /**
     * 查看设备
     * @param criteria
     * @return
     */
    @ApiOperation("查看设备信息")
    @GetMapping
    @PreAuthorize("@el.check('admin','equipment:list')")
    public ResponseEntity<Object> getEquipment(EquipmentOperationQuery criteria) throws ParseException {
        return new ResponseEntity<>(operationService.queryOperation(criteria), HttpStatus.OK);
    }

    /**
     * 情况设备运行记录
     */
    @ApiOperation("情况设备运行记录")
    @DeleteMapping
    @PreAuthorize("@el.check('admin','equipment:list')")
    public ResponseEntity<Object> del(){
        operationService.del();
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
